package hos.table.holder;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;

import hos.table.BaseTableAdapter;

/**
 * <p>Title: BaseTitleTableHolder </p>
 * <p>Description:  </p>
 * <p>Company: www.mapuni.com </p>
 *
 * @author : 蔡俊峰
 * @version : 1.0
 * @date : 2023-01-12 14:27
 */
public abstract class BaseTitleTableHolder {

    private final int layoutId;

    public BaseTitleTableHolder(int layoutId) {
        this.layoutId = layoutId;
    }

    public View onBindView(@NonNull Context context, @NonNull BaseTableAdapter adapter, String title) {
        return onBindView(context, layoutId, adapter,title);
    }

    public View onBindView(@NonNull Context context, int layoutId, @NonNull BaseTableAdapter adapter, String title) {
        View itemView = onBindView(adapter, View.inflate(context, layoutId, null),title);
        layoutParams(adapter,itemView);
        return itemView;
    }


    public abstract View onBindView(@NonNull BaseTableAdapter adapter, @NonNull View itemView, String title);

    void layoutParams(@NonNull BaseTableAdapter adapter, @NonNull View itemView){
        OnTableSizeListener listener = adapter.getOnTableSizeListener();
        if (listener == null) {
            return;
        }
        ViewGroup.LayoutParams layoutParams = itemView.getLayoutParams();
        if (layoutParams == null) {
            layoutParams = new ViewGroup.MarginLayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        }
        layoutParams.height = listener.columnHeaderHeight();
        layoutParams.width = listener.rowHeaderWidth();
        itemView.setLayoutParams(layoutParams);
    }
}
